//
//  HQYFoodModel.m
//  Go!
//
//  Created by rimi on 16/7/12.
//  Copyright © 2016年 黄秋燕. All rights reserved.
//

#import "HQYFoodScrollViewModel.h"
#import "NetWorkManager.h"

@interface HQYFoodScrollViewModel ()
@property (nonatomic, strong) NSMutableArray *dataSourceArray; /**< 数据源 */
@end

@implementation HQYFoodScrollViewModel
- (void)getList {
    // 改变self的弱引用
    __weak typeof(self) weakSelf = self;
    
    // 获取团单网络请求
    [NetWorkManager getWithURL:@"searchdeals" urlParam:@{@"city_id":[[NSUserDefaults standardUserDefaults] objectForKey:currentCity_ID], @"cat_ids":@"326", @"page_size":@"4"} successBlock:^(id responseObject) {
        weakSelf.response = responseObject[@"data"][@"deals"];
    } FailureBlock:nil];
}

/**< 返回数据的组数*/
- (NSInteger)getNumberOfRows {
    return self.dataSourceArray.count;
}

- (NSArray *)getDataArray {
    for (NSDictionary *dict in self.response) {
        [_dataSourceArray addObject:dict[@"image"]];
    }
    // 在数组末尾添加第一张图片
    [_dataSourceArray addObject:self.response[0][@"image"]];
    // 在数组首插入最后一张图片
    [_dataSourceArray insertObject:self.response[self.response.count - 2][@"image"] atIndex:0];
    
    return [_dataSourceArray copy];
}


- (NSMutableArray *)dataSourceArray {
    if (!_dataSourceArray) {
        _dataSourceArray = [NSMutableArray array];
    }
    return _dataSourceArray;
}
@end
